package com.gjy.nwpufindseats.Fragment;
import com.gjy.nwpufindseats.baseData.Global;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.TextView;
import com.gjy.nwpufindseats.MainActivity;
import com.gjy.nwpufindseats.R;

public class Fragment_roomlist extends Fragment implements OnClickListener {
	private View view;
	private TextView roomA;
	private TextView roomC;
	
	private TextView roomD;
	private TextView roomG;
	Context maincContext;
	 @Override
	    public View onCreateView(LayoutInflater inflater, ViewGroup container,
	    		Bundle savedInstanceState) {
	    	view = inflater.inflate(R.layout.fragment_roomlist, container, false);
	    	maincContext = getActivity();
	    	roomA = (TextView) view.findViewById(R.id.roomA);
	    	roomA.setOnClickListener(this); 
	    	roomC = (TextView) view.findViewById(R.id.roomC);
	    	roomC.setOnClickListener(this); 
	    	roomD = (TextView) view.findViewById(R.id.roomD);
	    	roomD.setOnClickListener(this); 
	    	roomG = (TextView) view.findViewById(R.id.roomG);
	    	roomG.setOnClickListener(this);
	    	
	    	return view;
	    }
	     
		@Override
		public void onClick(View v) {
			Fragment newContent = new Fragment_room();;
			Bundle bundle = new Bundle();	
			switch (v.getId()) {
			case R.id.roomA:
				bundle.putString("num", Global.apartmentNum[0]);
				bundle.putString("name", Global.apartmentName[0]);
				newContent.setArguments(bundle);
				break;
			case R.id.roomC:
				bundle.putString("num", Global.apartmentNum[1]);
				bundle.putString("name", Global.apartmentName[1]);
				newContent.setArguments(bundle);
				break;
			case R.id.roomD:
				bundle.putString("num", Global.apartmentNum[2]);
				bundle.putString("name", Global.apartmentName[2]);
				newContent.setArguments(bundle);
			break;
			case R.id.roomG:
				bundle.putString("num", Global.apartmentNum[3]);
				bundle.putString("name", Global.apartmentName[3]);
				newContent.setArguments(bundle);
				break;	
			default:
			break;
			}
			if (newContent != null)
				switchFragment(newContent);
		}
		 private void switchFragment(Fragment fragment) {
		 		if (getActivity() == null)
		 			return;	
		 			MainActivity ra = (MainActivity) getActivity();
		 			ra.switchContent(fragment);
		 		
		 	}

}
